package framework.command.impl;

import framework.account.IAccount;
import framework.account.IEntry;
import framework.command.ICommand;
import framework.factory.TransactionFactory;

public class WithdrawCommand implements ICommand {
    private IAccount account;
    private float amount;

    public WithdrawCommand(IAccount acc, float amount) {
        this.account = acc;
        this.amount = amount;
    }

    public void execute() {

        if (account.withdraw(amount)) {
            IEntry tr = TransactionFactory.createWithdrawTransaction(amount, "success");
            account.addTransaction(tr);
        } else {
            IEntry tr = TransactionFactory.createWithdrawTransaction(amount, "failed");
            account.addTransaction(tr);
        }
    }
}
